package Controller;

import java.io.IOException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class reBindServlet
 */
@WebServlet("/reBindServlet")
public class reBindServlet extends SerchBindServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see SerchBindServlet#SerchBindServlet()
     */
    public reBindServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		bindName=request.getParameter("bindName");
		bindValue=request.getParameter("bindValue");
		if(bindName!=null)
		{
			try {
				ctx.rebind(bindName,bindValue);
				response.getOutputStream().print("bind_name:"+bindName+" bind_value:"+bindValue);
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				response.getOutputStream().print("failed");
				e.printStackTrace();
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
